package com.advtower.towerapi.scheduled;

import com.advtower.towerapi.utils.HttpUtils;
import com.alibaba.fastjson.JSON;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author herman
 * @version 1.0
 * @date 2021/12/4 20:24
 */
@Component
public class OfferScheduled {

    @Scheduled(cron = "0 */10 * * * ?")
    public void syncAdvOffer(){
        String apiResult = null;
        try {
            //从mysql读取广告主信息包括url，apiResult map等
            //TODO
            String url = "http://api.furthermoreads.com/v2/offer/pull?token=a4b596524e5d4687adbd8085fbacf02f";
            apiResult = HttpUtils.httpGet(url);
            HashMap apiResultMap = JSON.parseObject(apiResult,HashMap.class);
            List<Map> offerList = (List)apiResultMap.get("data");
            for (Map offerMap : offerList) {
                System.out.println(offerMap.get("app_pack_name"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
